package org.aokey.springdemo3.July;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@RestController
public class MessageController {
    public List<MessageInfo> messageInfoList=new ArrayList<>();
    @RequestMapping(value = "/publish",produces = "Application/json")
    public String publicMessage(@RequestBody MessageInfo messageInfo){
        if(!StringUtils.hasLength(messageInfo.getMessage())
                || !StringUtils.hasLength(messageInfo.getFrom())
                || !StringUtils.hasLength(messageInfo.getTo())){
            return "{\"ok\": 0}";
        }
        messageInfoList.add(messageInfo);
        return "{\"ok\": 1}";
    }
    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageInfoList;
    }
}
